﻿<paging:MtPage x:Name="PageRoot"
               x:Class="SampleWindowsStoreApp.Views.DataGridPage"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
               xmlns:paging="using:MyToolkit.Paging"
               xmlns:viewModels="using:SampleWindowsStoreApp.ViewModels"
               xmlns:controls="using:MyToolkit.Controls"
               xmlns:models="using:SampleWindowsStoreApp.Models"
               mc:Ignorable="d">

    <paging:MtPage.Resources>
        <viewModels:DataGridPageModel x:Key="ViewModel" />
    </paging:MtPage.Resources>
    
    <Grid DataContext="{StaticResource ViewModel}" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Button Margin="39,59,39,0" Command="{Binding Frame.GoBackCommand, ElementName=PageRoot}"
                    Style="{StaticResource NavigationBackButtonNormalStyle}" VerticalAlignment="Top"
                    AutomationProperties.Name="Back" AutomationProperties.AutomationId="BackButton" 
                    AutomationProperties.ItemType="Navigation Button"/>

            <TextBlock Style="{StaticResource SubheaderTextStyle}" Text="Windows 8 and MyToolkit Sample App" 
                       Margin="0,50,0,10" Grid.Column="1" />
            <TextBlock Text="DataGrid" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                       TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,100,0,0"/>
        </Grid>

        <StackPanel Grid.Row="1" Margin="120,60,40,20">
            <TextBlock Text="Filter" FontWeight="Bold" Margin="0,0,0,10" Style="{StaticResource BaseTextBlockStyle}" />
            <TextBox Text="" TextChanged="OnFilterChanged" FontWeight="Bold" HorizontalAlignment="Left" Width="300" Margin="0,0,0,20" />
        </StackPanel>

        <Grid Grid.Row="2" Margin="120,0,40,20">
            <controls:DataGrid ItemsSource="{Binding People}" x:Name="DataGrid" SelectionMode="Multiple" 
                               SelectedItem="{Binding SelectedPerson, Mode=TwoWay}" SelectionChanged="OnSelectedItemsChanged"
                               DefaultOrderIndex="1">
                <controls:DataGrid.Columns>
                    <controls:DataGridTextColumn Width="200" Header="Firstname" Binding="{Binding Firstname}"
                                                 d:DataContext="{d:DesignInstance Type=models:Person}" />
                    <controls:DataGridTextColumn Width="200" Binding="{Binding Lastname}" IsAscendingDefault="False"
                                                 d:DataContext="{d:DesignInstance Type=models:Person}">
                        <controls:DataGridTextColumn.Header>
                            <TextBlock Text="Lastname" Foreground="Green" />
                        </controls:DataGridTextColumn.Header>
                    </controls:DataGridTextColumn>
                    <controls:DataGridTextColumn Width="200" Header="Category" Binding="{Binding Category}" 
                                                 d:DataContext="{d:DesignInstance Type=models:Person}" />
                </controls:DataGrid.Columns>
                <controls:DataGrid.ItemDetailsTemplate>
                    <DataTemplate>
                        <StackPanel Margin="10,10,10,5" d:DataContext="{d:DesignInstance Type=models:Person}">
                            <TextBlock Text="Details: " FontWeight="Bold" />
                            <TextBlock Text="{Binding Firstname}" />
                            <TextBlock Text="{Binding Lastname}" />
                        </StackPanel>
                    </DataTemplate>
                </controls:DataGrid.ItemDetailsTemplate>
            </controls:DataGrid>
        </Grid>
        
        <StackPanel Grid.Row="3" Margin="120,0,0,40">
            <TextBlock Text="Selected Item" FontWeight="Bold" Style="{StaticResource BaseTextBlockStyle}" Margin="0,0,0,5" />
            <TextBlock Text="{Binding SelectedPerson.Firstname}" Style="{StaticResource BaseTextBlockStyle}" Margin="0,0,0,20" />

            <TextBlock Text="Selected Items" FontWeight="Bold" Style="{StaticResource BaseTextBlockStyle}" Margin="0,0,0,5" />
            <TextBlock x:Name="SelectedItems" Style="{StaticResource BaseTextBlockStyle}" Margin="0,0,0,20" />
            
            <StackPanel Orientation="Horizontal">
                <Button Content="Select random Person" Click="OnSelectLastPerson" Margin="0,0,20,0" />
                <Button Content="Remove first Column" Click="OnRemoveFirstColumn" Margin="0,0,20,0" />
                <Button Content="Add removed Column" Click="OnAddRemovedColumn" Margin="0,0,20,0" />
                
                <Button Content="Add 10 elements" Click="OnAdd10Elements" Margin="0,0,20,0" />
            </StackPanel>
        </StackPanel>
    </Grid>
</paging:MtPage>
